package com.jiangxiaofei.citycloud.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.bean.WorkNumBean;
import com.jiangxiaofei.citycloud.constants.IntConstants;
import com.jiangxiaofei.citycloud.event.EventMessage;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * 作者: JiangXfei
 * 日期: 2017/10/11 0011
 */

public class RetruitWorkNumAdapter extends RecyclerView.Adapter<RetruitWorkNumAdapter.NumViewHolder> {
    private Context mContext;
    private List<WorkNumBean> numList;
    private int typeCode;

    public RetruitWorkNumAdapter(Context mContext, List<WorkNumBean> numList,int typeCode) {
        this.mContext = mContext;
        this.numList = numList;
        this.typeCode=typeCode;
    }

    @Override
    public NumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_retruit_work_num, parent, false);
        NumViewHolder viewHolder = new NumViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(NumViewHolder holder, int position) {
        holder.tvName.setText(numList.get(position).getName());
        holder.tvNumber.setText(numList.get(position).getNum());
        if (typeCode== IntConstants.FINDWORK){
            holder.tvType.setText("人");
        }else{
            holder.tvType.setText("份工作");
        }
        holder.view.setOnClickListener(view -> {
            EventMessage.WorkNumItemClickMsg workNumItemClickMsg = new EventMessage.WorkNumItemClickMsg(Integer.valueOf(numList.get(position).getId()));
            EventBus.getDefault().post(workNumItemClickMsg);
        });
    }

    @Override
    public int getItemCount() {
        return numList.size();
    }

    class NumViewHolder extends RecyclerView.ViewHolder {
        TextView tvName, tvNumber,tvType;
        View view;

        public NumViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_item_retruit_work_type);
            tvNumber = itemView.findViewById(R.id.item_tv_work_num);
            tvType=itemView.findViewById(R.id.items_tv_work_or_worker);
            view = itemView;
        }
    }
}
